package com.example.consumer.service;

/**
 * @Author: banban
 * @Desctription: TODO
 * @Date: Created in 2023/12/8 16:35
 * @Version: 1.0
 */
import com.alibaba.dubbo.config.annotation.Reference;
import com.example.consumer.mapper.UserMapper;
import com.example.imterface.entity.Product;
import com.example.imterface.entity.User;
import com.example.imterface.service.ProductService;
import com.example.imterface.service.UserService;
import com.example.imterface.util.ResultVOUtil;
import com.example.imterface.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
public class UserServiceImpl implements UserService {
    @Reference(loadbalance = "roundrobin")
    private ProductService productService;
    @Autowired
    private UserMapper userMapper;
    @Override
    public ResultVO getUserById(int id) {
        User user=userMapper.selectById(id);
        Product product1=(Product) productService.getProductById(1).getData();
        Product product2=(Product) productService.getProductById(2).getData();
        user.setProductList(Arrays.asList(product1,product2));
        return ResultVOUtil.success(user);
    }
}


